package io.github.biezhi.elves.mapper;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.github.biezhi.elves.sgggzy.model.SgBiddingList;
import io.github.biezhi.elves.sgggzy.model.SgDownloadBiddingHtml;
import io.github.biezhi.elves.sgggzy.model.SgRecordBiddingNotice;

public interface SgggzyMapper {

	/**
	 * 新增记录公告标题,公告网址数据
	 * @param	RecordBiddingNotice
	 */
	@Insert("INSERT INTO t_record_sg (id, notice_type,keyword, title, notice_detail_url, size, pubdate) "
			+"VALUES (#{id},#{noticeType}, #{keyword}, #{title}, #{noticeDetailUrl}, #{size}, #{pubdate})")
	void saveSgRecordBiddingNotice(SgRecordBiddingNotice sgRecordBiddingNotice);

	/**
	 * 查看相同noticeDetailUrl条数
	 * @param noticeDetailUrl
	 * @return
	 */
	@Select("SELECT count(*) FROM t_record_sg "
			+"WHERE notice_detail_url = #{noticeDetailUrl} ")
	Integer countByUrl(String noticeDetailUrl);
	
	/**
	 * 查看相同noticeDetailUrl条数
	 * @param noticeDetailUrl
	 * @return
	 */
	@Select("SELECT count(*) FROM t_download_sg "
			+"WHERE notice_detail_url = #{noticeDetailUrl} ")
	Integer countByDownloadUrl(String noticeDetailUrl);

	/**
	 * 根据公告类型和发布日期查询记录表
	 * @param noticeType
	 * @param pubdate
	 * @return
	 */
	@Select("select id as id,notice_type as noticeType,notice_detail_url as noticeDetailUrl,"
			+ "purchase_mode as purchaseMode,keyword as keyword,pubdate as pubdate from t_record_sg "
			+ "where notice_type=#{noticeType} and SUBSTR(pubdate,1,4)=#{date}")
	List<SgRecordBiddingNotice> findRecordByNoticeTypeAndDate(@Param("noticeType") String noticeType, @Param("date") String date);

	/**
	 * 保存SgDownloadBiddingHtml对象到t_download_sg表中
	 * @param sgDownloadBiddingHtml
	 */
	@Insert("insert into t_download_sg(notice_detail_url,tab_type,notice_type,keyword,html_content,download_file,pubdate)"
			+ "values (#{noticeDetailUrl},#{tabType},#{noticeType},#{keyword},#{htmlContent},#{downloadFile},#{pubdate})")
	void saveSgDownloadBiddingHtml(SgDownloadBiddingHtml sgDownloadBiddingHtml);

	/**
	 * 查询t_download_sg表所有数据
	 * @return
	 */
	@Select("select id as id,notice_detail_url as noticeDetailUrl,notice_type as noticeType,"
			+ "purchase_mode as purchaseMode,keyword as keyword,html_content as htmlContent,"
			+ "download_file as downloadFile,pubdate as pubdate from t_download_sg")
	List<SgDownloadBiddingHtml> listDownloadHtml();
	
	/**
	 * 根据tab_type查询t_download_sg表数据
	 * @return
	 */
	@Select("select id as id,notice_detail_url as noticeDetailUrl,notice_type as noticeType,"
			+ "purchase_mode as purchaseMode,keyword as keyword,html_content as htmlContent,"
			+ "download_file as downloadFile,pubdate as pubdate from t_download_sg "
			+ "where tab_type=#{tabType}")
	List<SgDownloadBiddingHtml> listDownloadHtmlByTabType(@Param("tabType") String tabType);

	/**
	 * 保存sgbiddingList对象到t_bidding_list_zq表中
	 * @param sgbiddingList
	 */
	@Insert("insert into t_bidding_list_zq_sg(NOTICE_TITLE,PRJ_ID,PRJ_NAME,NOTICE_NAME,BUY_TYPE,"
			+ "CUSTOMER,SUPPLIER,BUDGET,BID_PRICE,PUBLISH_TIME,DEAL_TIME,INDUSTRY,BID_URL,CITY,"
			+ "IS_SPECIAL,SPECIAL_NAME,PUBDATE,PROJ_TYPE) values (#{noticeTitle},#{prjId},#{prjName},"
			+ "#{noticeName},#{buyType},#{customer},#{supplier},#{budget},#{bidPrice},#{publishTime},"
			+ "#{dealTime},#{industry},#{bidUrl},#{city},#{isSpecial},#{specialName},#{pubdate},#{projType})")
	void saveSgbiddingList(SgBiddingList sgbiddingList);
}
